package com.pjb.springbootjjwt.store.entity;

import com.pjb.springbootjjwt.store.Defines;
import com.pjb.springbootjjwt.store.Sql;
import com.pjb.springbootjjwt.store.utils.FileUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.util.List;

@Data
@Builder
@AllArgsConstructor
public class Define {

    private List<Integer> fieldsLength;

    private List<String> fields;

    private String engine;

    private String pk;

    private List<String> uk;
    private String ddl;

    public Define(String ddl) {
        this.ddl = ddl;
        Sql sql = Sql.getInstance();
        this.fields = sql.getFields(ddl);
        this.fieldsLength = Defines.getFieldsLengths(ddl);
        this.pk = sql.getPK(ddl);
        this.engine = Defines.getEngine(ddl);
    }

//    public Define(String ddl, String engine) {
//        this.ddl = ddl;
//        this.engine = engine;
//    }

    public static String toJson(String ddl) {
        return toJson(new Define(ddl));
    }

    public static String toJson(Define define) {
        return FileUtil.jsonStr(define);
    }

//    public static void main(String[] args) {
//        Define define = new Define("create table test(a vchar(10), b vchar(10), c vchar(10), primary key(a)) ENGINE = myisam");
//        String j = FileUtil.jsonStr(define);
//        System.out.println(j);
//        System.out.println(toJson("create table test(a vchar, b vchar, c vchar, primary key(a)) engine = csv"));
//        System.out.println(toJson("create table test(a vchar, b vchar, c vchar, primary key(a))"));
//    }
}
